<template>
	<view>
		<u-form :model="form" ref="uform" :rules="rules" label-width="240rpx" :error-type="errorType">
		  <u-form-item :label="item.title" prop="value" :required="item.must">
			  <u-upload
				:action="uploadUrl"
				:header="uploadHeader"
				max-count="1"
				:multiple="false"
				:file-list="form.value"
				@on-remove="handleAvatarRemove"
				@on-success="handleAvatarSuccess"></u-upload>
		  </u-form-item>
		</u-form>
	</view>
</template>

<script>
export default {
  props: ["item", "number", "uploadHeader", "uploadUrl"],
  data() {
    return {
	  errorType: ['message'],
      form: {
        value: [],
      },
      rules: {
        value: [
          { required: this.item.must, type: 'array', message: this.item.msg, trigger: "change" },
        ],
      },
    };
  },
  methods: {
	handleAvatarSuccess(res, index, lists) {
	  this.form.value = lists;
	  this.$emit("changeComponent", {
		number: this.number,
		type: this.item.type,
		value: this.form.value,
	  });
	},
	handleAvatarRemove(index,lists) {
	  this.form.value = lists;
	  this.$emit("changeComponent", {
	  		number: this.number,
	  		type: this.item.type,
	  		value: [],
	  });
	}
  },
  mounted() {
		this.form = {
		  ...this.form,
		  ...this.item,
		};
		this.$refs.uform.setRules(this.rules);
  	}
};
</script>

<style>
</style>
